package mil.af.amc.adpetracker.web.actions.struts1.DrmoPackage;

import mil.af.amc.adpetracker.web.actions.struts1.AbstractAction;
import mil.af.amc.adpetracker.service.DrmoPackageService;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Struts Action to close (complete) a DRMO Package
 *
 * Closing a package means that these items have been turned in to DRMO, not that the package is
 * no longer needed.
 *
 * @author TSgt Jason Ferguson
 */

public class CloseDrmoPackageAction extends AbstractAction {

    private static final Log log = LogFactory.getLog(CloseDrmoPackageAction.class);

    private DrmoPackageService drmoPackageService;

    public void setDrmoPackageService(DrmoPackageService drmoPackageService) {
        this.drmoPackageService = drmoPackageService;
    }

    @Override
    public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {

        int packageId = Integer.parseInt(httpServletRequest.getParameter("drmoPackageId"));

        drmoPackageService.closePackage(packageId);
        log.trace("CloseDrmoPackageAction completed for DRMO Package ID " + packageId);

        return actionMapping.findForward("success");
    }
}
